/*******************************************************************************
* Copyright (C) 2019 China Micro Semiconductor Limited Company. All Rights Reserved.
*
* This software is owned and published by:
* CMS LLC, No 2609-10, Taurus Plaza, TaoyuanRoad, NanshanDistrict, Shenzhen, China.
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with CMS
* components. This software is licensed by CMS to be adapted only
* for use in systems utilizing CMS components. CMS shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. CMS is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/

/****************************************************************************/
/** \file main.c
**
** 
**
**	History:
**	
*****************************************************************************/
/****************************************************************************/
/*	include files
*****************************************************************************/
#include "cms8s6990.h"
#include "Temp_Table.h"
/****************************************************************************/
/*	Local pre-processor symbols('#define')
*****************************************************************************/

/****************************************************************************/
/*	Global variable definitions(declared in header file with 'extern')
*****************************************************************************/


/****************************************************************************/
/*	Local type definitions('typedef')
*****************************************************************************/

/****************************************************************************/
/*	Local variable  definitions('static')
*****************************************************************************/
uint32_t Systemclock = 24000000;

/****************************************************************************/
/*	Local function prototypes('static')
*****************************************************************************/


/****************************************************************************/
/*	Function implementation - global ('extern') and local('static')
*****************************************************************************/

/*****************************************************************************
 ** \brief	 main
 **
 ** \param [in]  none   
 **
 ** \return 0
 *****************************************************************************/
 xdata int16_t 	GusMainMenuBuf[19] = {100, 10, 110, 0, 30, 2, 120, 30, 80, 20, 0, 0,			/* 主菜单缓存数组 		 			*/
									   0, -40, 999, 2, 2, 50,610};												/* 工程师菜单缓存数组 	 			*/

 
 
/**
  * @brief  Flash写半字函数
  * @param  Addr写入的地址 0x00~0x3FFF;
  * @param  Data，要写入的数据
  * @retval 无
  */
void FLASH_WriteHalfWord(uint16_t Addr, int16_t Data)
{
	FLASH_UnLock();
	FLASH_Erase(FLASH_DATA,Addr);
	FLASH_Write(FLASH_DATA,Addr, Data);
	FLASH_Write(FLASH_DATA,Addr+1, Data>>8);
	FLASH_Lock();
//	delay_ms(5);
}
/**
  * @brief  Flash读半字函数
  * @param  Addr，要读取的地址
  * @retval 读取的半字
  */
int16_t FLASH_ReadHalfWord(uint16_t Addr)
{
	int16_t temp=0;
	FLASH_UnLock();
	temp = FLASH_Read(FLASH_DATA,Addr+1) << 8 | FLASH_Read(FLASH_DATA,Addr);		
	FLASH_Lock();
	return temp;
}
/**
  * @brief  Flash写数组函数，默认写入一页（1k）
  * @param  Addr写入的地址 0x00~0x3FFF;
  * @param  Data，要写入的数据（数组）
  * @retval 无
  */
void FLASH_WritePage(uint16_t Addr, int16_t* Data)
{
	uint16_t i = 0;
	FLASH_UnLock();
	FLASH_Erase(FLASH_DATA,Addr);
	for(i = 0; i < 450 * 2; i += 2)
	{
		FLASH_Write(FLASH_DATA, Addr + i, Data[i/2]);
		FLASH_Write(FLASH_DATA, Addr + i+1, Data[i/2] >> 8);
	}
	FLASH_Lock();
}

static void MenuFlash_Init(void)
{
	GusMainMenuBuf[0] 	= 87;
	GusMainMenuBuf[1]	= 10;
	GusMainMenuBuf[2]	= 60;
	GusMainMenuBuf[3]	= 0;
	GusMainMenuBuf[4]	= 18;
	GusMainMenuBuf[5]	= 2;
	GusMainMenuBuf[6]	= 33;
	GusMainMenuBuf[7]	= 3;
	GusMainMenuBuf[8]	= 80;
	GusMainMenuBuf[9]	= 20;
	GusMainMenuBuf[10]	= 0;
	GusMainMenuBuf[11]	= 0;
	GusMainMenuBuf[12] 	= 0;
	GusMainMenuBuf[13]	= -50;
	GusMainMenuBuf[14]	= 999;
	GusMainMenuBuf[15]	= 2;
	GusMainMenuBuf[16]	= 2;
	GusMainMenuBuf[17]	= 50;
	GusMainMenuBuf[18] 	= 610;
	FLASH_WritePage(0x3D5, GusMainMenuBuf);							/* 写入flash最后一页					 								*/
}

int main(void)
{		
	FLASH_WritePage(0x000, (int16_t*)GusTempBuf);
	MenuFlash_Init();
	while(1)
	{	
		;

	}
}






















